package com.musifind.adapters;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.musifind.activities.R;
import com.musifind.common.GeneralHelper;
import com.musifind.models.MatchedUsersItems;

public class MatchedUserListAdapter extends ArrayAdapter<MatchedUsersItems> {

	Context context;
	int layoutResourceId;
	ArrayList<MatchedUsersItems> objects = new ArrayList<MatchedUsersItems>();
	MatchedUsersItems matchItems;

	public MatchedUserListAdapter(Context context, int layoutResourceId, ArrayList<MatchedUsersItems> objects) {
		super(context, layoutResourceId, objects);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
		this.objects = objects;
	}

	public static class MatchedUsersHolder {
		ImageView imgUser;
		TextView txtUserName;
		// ToggleButton tglIsOnline;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		View row = convertView;

		MatchedUsersHolder holder;

		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent, false);

			holder = new MatchedUsersHolder();
			holder.imgUser = (ImageView) row.findViewById(R.id.imgMatchedUserPicture);
			holder.txtUserName = (TextView) row.findViewById(R.id.txtMatchedPersonName);
			// holder.tglIsOnline = (ToggleButton) row.findViewById(R.id.tglIsOnline);
			row.setTag(holder);
		}
		holder = (MatchedUsersHolder) row.getTag();

		final MatchedUsersItems mItems = objects.get(position);

		holder.imgUser.setImageBitmap(GeneralHelper.roundCornerImage(mItems.getUserImage(), 95));
		holder.txtUserName.setText(mItems.getUserName());
		// holder.tglIsOnline.setChecked(mItems.isOnline());
		// holder.tglIsOnline.setClickable(false);
		return row;

	}
}